package com.sun.springAssert;

import org.springframework.util.Assert;

/**
 * <p>方法入参进行合法性校验
 * <ul>
 * <li>Assert.notNull(Object object, "object is required") - 对象非空 </li> 
 * <li>Assert.isTrue(Object object, "object must be true")   -    对象必须为true   
 * <li>Assert.notEmpty(Collection collection, "collection must not be empty")    -    集合非空  
 * <li>Assert.hasLength(String text, "text must be specified")   -    字符不为null且字符长度不为0   
 * <li>Assert.hasText(String text, "text must not be empty")    -     text 不为null且必须至少包含一个非空格的字符  
 * <li>Assert.isInstanceOf(Class clazz, Object obj, "clazz must be of type [clazz]")    -    obj必须能被正确造型成为clazz 指定的类</li>
 * </ul>
 * <p>throw new IllegalArgumentException 断言都会抛出此异常,可以做全局的异常捕获
 * @author SunAFei
 * @time 2018年1月17日 下午5:46:39
 * 
 */
public class SpringAssert {

	public static void test1(String param) {
		Assert.hasLength(param, "param不能为空");
		Assert.isTrue(false, "object must be true");
		System.out.println("检查通过.....");
	}
	
	public static void main(String[] args) {
		try {
			test1(null);
		} catch (IllegalArgumentException e) {//IllegalArgumentException此异常表明向方法传递了一个不合法或不正确的参数
			e.printStackTrace();
		}
	}

}
